<?php
/**
 * Created by PhpStorm.
 * User: Edward
 * Date: 2019/5/30
 * Time: 14:07
 */

namespace app\Validate;


use app\lib\exception\ParameterException;
use think\facade\Request;
use think\Validate;

class BaseValidate extends Validate {


    public function goCheck(){
        $params = Request::param();
        $result = $this->check($params);
        if(!$result){
            $exception = new ParameterException([
                'msg' =>  $this->error,
                ]);
            throw $exception;
        }else{
            return $params;
        }
    }

    protected function isPositiveInteger($value,$rule='',$data='',$filed=''){
        if(is_numeric($value) && is_int($value+0) &&($value+0)>0){
            return true;
        }else{
            return false;
        }
    }

    protected function checkIDs($value,$rule='',$data='',$filed=''){
        $values = explode(',',$value);

        if(empty($values)){
            return false;
        }
        foreach ($values as $id){
            if(!$this->isPositiveInteger($id)){
                return false;
            }
        }
        return true;
    }
}
